package jrdesktop.viewer.main;

import jrdesktop.viewer.main.FileMng.FilesDropTargetListener;
import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.dnd.DropTarget;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Hashtable;
import java.util.zip.Deflater;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import jrdesktop.AboutGui;
import jrdesktop.main;

/**
 * ViewerGUI.java
 * @author  benbac
 */

public class ViewerGUI extends javax.swing.JFrame {
        
    private final byte COLOR_FULL = 0;
    private final byte COLOR_16_BIT = 1;
    private final byte COLOR_256 = 2;
    private final byte COLOR_GRAY = 3;
    //private final byte COLOR_2 = 4;    
    
    private boolean fullScreenMode = false;
    
    private Recorder recorder;
    
    /** Creates new form MainFrame */
    public ViewerGUI(Recorder recorder) {        
        this.recorder = recorder;
        initComponents();
        initScreenPlayer();
        setIconImage(new ImageIcon(main.IDLE_ICON).getImage());                  
        setVisible(true);
    }
    
    public void initScreenPlayer() {
        jPanel1.setLayout(new BorderLayout()); 
        jPanel1.add(recorder.screenPlayer);
        new DropTarget(recorder.screenPlayer, 
                new FilesDropTargetListener(recorder.screenPlayer, recorder));
    }   

    public void Start() {
        jBtnStartStopActionPerformed(null);               
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenuFileTranfer = new javax.swing.JPopupMenu();
        jMenuItemSendFiles = new javax.swing.JMenuItem();
        jMenuItemReceiveFiles = new javax.swing.JMenuItem();
        jToolBar1 = new javax.swing.JToolBar();
        jBtnStartStop = new javax.swing.JButton();
        jBtnPauseContinue = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jBtnViewCtrl = new javax.swing.JButton();
        jBtnFullNormal = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jBtnPartialComplete = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxSc = new javax.swing.JComboBox();
        jSeparator7 = new javax.swing.JToolBar.Separator();
        jCheckBoxDC = new javax.swing.JCheckBox();
        jComboBoxCL = new javax.swing.JComboBox();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jBtnAbout = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jToolBar2 = new javax.swing.JToolBar();
        jCheckBoxCQ = new javax.swing.JCheckBox();
        jSlider1 = new javax.swing.JSlider();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxColorQuality = new javax.swing.JComboBox();
        jSeparator6 = new javax.swing.JToolBar.Separator();
        jCheckBoxClipTrans = new javax.swing.JCheckBox();
        jButtonFileTransfer = new javax.swing.JButton();
        jSeparator8 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jButtonConnectionInfos = new javax.swing.JButton();

        jMenuItemSendFiles.setText("Send files");
        jMenuItemSendFiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSendFilesActionPerformed(evt);
            }
        });
        jPopupMenuFileTranfer.add(jMenuItemSendFiles);

        jMenuItemReceiveFiles.setText("Receive files");
        jMenuItemReceiveFiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemReceiveFilesActionPerformed(evt);
            }
        });
        jPopupMenuFileTranfer.add(jMenuItemReceiveFiles);

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Java Remote Desktop [jrdesktop] 0.2 Beta");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jToolBar1.setRollover(true);
        jToolBar1.setAlignmentY(0.5F);
        jToolBar1.setMaximumSize(new java.awt.Dimension(713, 35));

        jBtnStartStop.setText("Start");
        jBtnStartStop.setFocusable(false);
        jBtnStartStop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnStartStop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnStartStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnStartStopActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnStartStop);

        jBtnPauseContinue.setText("Pause");
        jBtnPauseContinue.setFocusable(false);
        jBtnPauseContinue.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnPauseContinue.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnPauseContinue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnPauseContinueActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnPauseContinue);
        jToolBar1.add(jSeparator2);

        jBtnViewCtrl.setText("View only");
        jBtnViewCtrl.setFocusable(false);
        jBtnViewCtrl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnViewCtrl.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnViewCtrl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnViewCtrlActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnViewCtrl);

        jBtnFullNormal.setText("Full screen");
        jBtnFullNormal.setFocusable(false);
        jBtnFullNormal.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnFullNormal.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnFullNormal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnFullNormalActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnFullNormal);
        jToolBar1.add(jSeparator1);

        jBtnPartialComplete.setText("Custom screen");
        jBtnPartialComplete.setFocusable(false);
        jBtnPartialComplete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnPartialComplete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnPartialComplete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnPartialCompleteActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnPartialComplete);
        jToolBar1.add(jSeparator3);

        jLabel2.setText("Screen scale ");
        jToolBar1.add(jLabel2);

        jComboBoxSc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "25", "50", "75", "100", "125", "150", "200" }));
        jComboBoxSc.setSelectedIndex(3);
        jComboBoxSc.setFocusable(false);
        jComboBoxSc.setMaximumSize(new java.awt.Dimension(50, 20));
        jComboBoxSc.setMinimumSize(new java.awt.Dimension(50, 20));
        jComboBoxSc.setPreferredSize(new java.awt.Dimension(50, 20));
        jComboBoxSc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxScItemStateChanged(evt);
            }
        });
        jToolBar1.add(jComboBoxSc);
        jToolBar1.add(jSeparator7);

        jCheckBoxDC.setSelected(true);
        jCheckBoxDC.setText("Data compression");
        jCheckBoxDC.setFocusable(false);
        jCheckBoxDC.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jCheckBoxDC.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jCheckBoxDC.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxDCActionPerformed(evt);
            }
        });
        jToolBar1.add(jCheckBoxDC);

        jComboBoxCL.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Best compression", "Best speed", "Default compression", "Default strategy", "Deflated", "Filtered", "Huffman only", "No compression" }));
        jComboBoxCL.setSelectedIndex(2);
        jComboBoxCL.setFocusable(false);
        jComboBoxCL.setMaximumSize(new java.awt.Dimension(150, 20));
        jComboBoxCL.setMinimumSize(new java.awt.Dimension(150, 20));
        jComboBoxCL.setPreferredSize(new java.awt.Dimension(150, 20));
        jComboBoxCL.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxCLItemStateChanged(evt);
            }
        });
        jToolBar1.add(jComboBoxCL);
        jToolBar1.add(jSeparator4);

        jBtnAbout.setText("About");
        jBtnAbout.setFocusable(false);
        jBtnAbout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnAbout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnAboutActionPerformed(evt);
            }
        });
        jToolBar1.add(jBtnAbout);

        jPanel1.setBackground(java.awt.Color.black);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 872, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 354, Short.MAX_VALUE)
        );

        jToolBar2.setRollover(true);
        jToolBar2.setAlignmentY(0.5F);
        jToolBar2.setMaximumSize(new java.awt.Dimension(807, 35));

        jCheckBoxCQ.setSelected(true);
        jCheckBoxCQ.setText("JPEG CQ");
        jCheckBoxCQ.setFocusable(false);
        jCheckBoxCQ.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jCheckBoxCQ.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxCQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxCQActionPerformed(evt);
            }
        });
        jToolBar2.add(jCheckBoxCQ);

        jSlider1.setMajorTickSpacing(1);
        jSlider1.setMaximum(10);
        jSlider1.setMinorTickSpacing(1);
        jSlider1.setPaintTicks(true);
        jSlider1.setValue(7);
        jSlider1.setFocusable(false);
        jSlider1.setMaximumSize(new java.awt.Dimension(100, 33));
        jSlider1.setMinimumSize(new java.awt.Dimension(100, 33));
        jSlider1.setPreferredSize(new java.awt.Dimension(100, 33));
        jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider1StateChanged(evt);
            }
        });
        jToolBar2.add(jSlider1);
        jToolBar2.add(jSeparator5);

        jLabel1.setText("Color quality ");
        jToolBar2.add(jLabel1);

        jComboBoxColorQuality.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Full colors", "16 bit colors", "256 colors", "Gray color" }));
        jComboBoxColorQuality.setFocusable(false);
        jComboBoxColorQuality.setLightWeightPopupEnabled(false);
        jComboBoxColorQuality.setMaximumSize(new java.awt.Dimension(100, 20));
        jComboBoxColorQuality.setMinimumSize(new java.awt.Dimension(100, 20));
        jComboBoxColorQuality.setPreferredSize(new java.awt.Dimension(100, 20));
        jComboBoxColorQuality.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxColorQualityItemStateChanged(evt);
            }
        });
        jToolBar2.add(jComboBoxColorQuality);
        jToolBar2.add(jSeparator6);

        jCheckBoxClipTrans.setSelected(true);
        jCheckBoxClipTrans.setText("Clipboard transfer");
        jCheckBoxClipTrans.setFocusable(false);
        jCheckBoxClipTrans.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jCheckBoxClipTrans.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBoxClipTrans.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxClipTransActionPerformed(evt);
            }
        });
        jToolBar2.add(jCheckBoxClipTrans);

        jButtonFileTransfer.setText("File transfer");
        jButtonFileTransfer.setFocusable(false);
        jButtonFileTransfer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonFileTransfer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonFileTransfer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFileTransferActionPerformed(evt);
            }
        });
        jToolBar2.add(jButtonFileTransfer);
        jToolBar2.add(jSeparator8);

        jButton1.setText("Server properties");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton1);

        jButtonConnectionInfos.setText("Connections infos");
        jButtonConnectionInfos.setFocusable(false);
        jButtonConnectionInfos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonConnectionInfos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonConnectionInfos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConnectionInfosActionPerformed(evt);
            }
        });
        jToolBar2.add(jButtonConnectionInfos);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-880)/2, (screenSize.height-450)/2, 880, 450);
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnStartStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnStartStopActionPerformed
        if (recorder.isRecording())
            recorder.Stop();
        else
            recorder.Start();
        
        if (recorder.isRecording()) {  
            setIconImage(new ImageIcon(main.ALIVE_ICON).getImage());            
            jBtnStartStop.setText("Stop");                  
        } else {
            jBtnStartStop.setText("Start");
            jBtnPauseContinue.setText("Pause");
            jBtnViewCtrl.setText("View only");
            jBtnFullNormal.setText("Full screen");
            jBtnPartialComplete.setText("Custom screen");
            setIconImage(new ImageIcon(main.IDLE_ICON).getImage());      
        }
    }//GEN-LAST:event_jBtnStartStopActionPerformed

    private void jBtnPauseContinueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnPauseContinueActionPerformed
        if (recorder.isRecording()) {
            recorder.setPause(!recorder.isPaused());
            if (recorder.isPaused())
                jBtnPauseContinue.setText("Resume");
            else
                jBtnPauseContinue.setText("Pause");
        }
    }//GEN-LAST:event_jBtnPauseContinueActionPerformed

    private void jBtnViewCtrlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnViewCtrlActionPerformed
        recorder.setViewOnly(!recorder.isViewOnly());
        if (recorder.isViewOnly())
            jBtnViewCtrl.setText("Full control");
        else
            jBtnViewCtrl.setText("View only");        
    }//GEN-LAST:event_jBtnViewCtrlActionPerformed

    private void jBtnFullNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnFullNormalActionPerformed
        changeFullScreenMode();
    }//GEN-LAST:event_jBtnFullNormalActionPerformed

    private void jBtnPartialCompleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnPartialCompleteActionPerformed
        if (recorder.isRecording()) {
            if (recorder.screenPlayer.isPartialScreenMode()) {
                jBtnPartialComplete.setText("Custom screen");
                recorder.screenPlayer.stopSelectingMode();
            } else
                recorder.screenPlayer.startSelectingMode();
        }
    }//GEN-LAST:event_jBtnPartialCompleteActionPerformed

    private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged
        if (jSlider1.getValueIsAdjusting()) {
            recorder.viewerData.setCompressionQuality((float)jSlider1.getValue() / 10.0f); 
            if (recorder.isRecording()) recorder.viewer.updateOptions();
        }
    }//GEN-LAST:event_jSlider1StateChanged

    private void jCheckBoxCQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxCQActionPerformed
        jSlider1.setEnabled(jCheckBoxCQ.isSelected());
        if (!jCheckBoxCQ.isSelected())
            recorder.viewerData.setCompressionQuality(-1);
        else
           recorder.viewerData.setCompressionQuality((float)jSlider1.getValue() / 10.0f); 
        if (recorder.isRecording()) recorder.viewer.updateOptions();
}//GEN-LAST:event_jCheckBoxCQActionPerformed

    private void jBtnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnAboutActionPerformed
        AboutGui.main(null);
}//GEN-LAST:event_jBtnAboutActionPerformed

    private void jComboBoxColorQualityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxColorQualityItemStateChanged
        setColorQuality(jComboBoxColorQuality.getSelectedIndex());
}//GEN-LAST:event_jComboBoxColorQualityItemStateChanged

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (evt.getID() == WindowEvent.WINDOW_CLOSING) {
            if (JOptionPane.showConfirmDialog(this, "Exit Viewer ?") == 
                    JOptionPane.YES_OPTION) {
                if (recorder.isRecording())                    
                    recorder.viewer.Stop();
                dispose();
            }
        }
        else
            super.processWindowEvent(evt);
    }//GEN-LAST:event_formWindowClosing

    private void jCheckBoxDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxDCActionPerformed
        jComboBoxCL.setEnabled(jCheckBoxDC.isSelected());
        recorder.viewerData.setDataCompression(jCheckBoxDC.isSelected());
        if (recorder.isRecording()) recorder.viewer.updateOptions();
}//GEN-LAST:event_jCheckBoxDCActionPerformed

    private void jComboBoxScItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxScItemStateChanged
        recorder.viewerData.setScreenScale(
                Float.valueOf(jComboBoxSc.getSelectedItem().toString()) / 100.0f);
        if (recorder.isRecording()) recorder.viewer.updateOptions();
}//GEN-LAST:event_jComboBoxScItemStateChanged

    private void jComboBoxCLItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxCLItemStateChanged
        setCompressionLevel(jComboBoxCL.getSelectedIndex());
    }//GEN-LAST:event_jComboBoxCLItemStateChanged

    private void jCheckBoxClipTransActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxClipTransActionPerformed
        setClipboardTransfer(jCheckBoxClipTrans.isSelected());
    }//GEN-LAST:event_jCheckBoxClipTransActionPerformed

    private void jButtonFileTransferActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileTransferActionPerformed
        jPopupMenuFileTranfer.show(jButtonFileTransfer, 15, 15);
    }//GEN-LAST:event_jButtonFileTransferActionPerformed

    private void jMenuItemSendFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSendFilesActionPerformed
        if (!recorder.isRecording()) return;
        File[] files = recorder.clipbrdUtility.getFilesFromClipboard(); 
        if (files.length == 0) { // no files in clipboard, return
            JOptionPane.showMessageDialog(ViewerGUI.this, 
                            "No file in clipboard !!", 
                            "Information", JOptionPane.INFORMATION_MESSAGE);            
            return;
        }    
        recorder.fileManager.setFiles(files);
        recorder.viewer.AddObject(new File("."));
    }//GEN-LAST:event_jMenuItemSendFilesActionPerformed

    private void jMenuItemReceiveFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemReceiveFilesActionPerformed
        if (!recorder.isRecording()) return;     
        recorder.viewer.AddObject(new File("..")); 
    }//GEN-LAST:event_jMenuItemReceiveFilesActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (!recorder.isRecording()) return;     
        recorder.viewer.AddObject(new Hashtable(0));      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonConnectionInfosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectionInfosActionPerformed
        if (!recorder.isRecording()) return;
        recorder.connectionInfos.display();
    }//GEN-LAST:event_jButtonConnectionInfosActionPerformed
     
    /**
     * @param args the command line arguments
     */
   /* public static void main(final String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ViewerGUI().setVisible(true);
            }
        });
    } */  
    
    public boolean isFullScreenMode () {
        return fullScreenMode;
    }
    
    public void changeFullScreenMode() {        
        GraphicsDevice device = getGraphicsConfiguration().getDevice();
        if (!device.isFullScreenSupported()) return;
        
        fullScreenMode = !fullScreenMode;
        
        if (fullScreenMode) {  // Full screen mode
                dispose();
                setUndecorated(true);
                device.setFullScreenWindow(this);
                setVisible(true);
                jBtnFullNormal.setText("Normal screen");
        }
        else {     // Normal screen mode
                dispose();
                setUndecorated(false);
                device.setFullScreenWindow(null);
                setVisible(true);
                jBtnFullNormal.setText("Full screen");
        }  
    }        

    public void setColorQuality(int colorQuality) {
        switch (colorQuality) {
            case COLOR_FULL: colorQuality = BufferedImage.TYPE_INT_ARGB; break;
            case COLOR_16_BIT: colorQuality = BufferedImage.TYPE_USHORT_555_RGB; break;
            case COLOR_256: colorQuality = BufferedImage.TYPE_BYTE_INDEXED; break;
            case COLOR_GRAY: colorQuality = BufferedImage.TYPE_BYTE_GRAY; break;
            //case COLOR_2: colorQuality = BufferedImage.TYPE_BYTE_BINARY; break;
        }
        recorder.viewerData.setColorQuality(colorQuality);
        if (recorder.isRecording()) recorder.viewer.updateOptions();                
    }
        
    public void setCompressionLevel(int index) {
        int level = Deflater.DEFAULT_COMPRESSION;                
        switch(index) {
            case 0: level = Deflater.BEST_COMPRESSION; break;
            case 1: level = Deflater.BEST_SPEED; break;
            case 2: level = Deflater.DEFAULT_COMPRESSION; break;
            case 3: level = Deflater.DEFAULT_STRATEGY; break;
            case 4: level = Deflater.DEFLATED; break;
            case 5: level = Deflater.FILTERED; break;
            case 6: level = Deflater.HUFFMAN_ONLY; break;
            case 7: level = Deflater.NO_COMPRESSION; break;    
        }
        recorder.viewerData.setCompressionLevel(level);
        if (recorder.isRecording()) recorder.viewer.updateOptions();        
    }
    
    public void setClipboardTransfer(boolean bool) {
         recorder.viewerData.setClipboardTransfer(bool);
        if (bool)
            recorder.clipbrdUtility.addFlavorListener();
        else
            recorder.clipbrdUtility.removeFlavorListener();
        if (recorder.isRecording()) recorder.viewer.updateOptions();       
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnAbout;
    private javax.swing.JButton jBtnFullNormal;
    public javax.swing.JButton jBtnPartialComplete;
    private javax.swing.JButton jBtnPauseContinue;
    private javax.swing.JButton jBtnStartStop;
    private javax.swing.JButton jBtnViewCtrl;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonConnectionInfos;
    private javax.swing.JButton jButtonFileTransfer;
    private javax.swing.JCheckBox jCheckBoxCQ;
    private javax.swing.JCheckBox jCheckBoxClipTrans;
    private javax.swing.JCheckBox jCheckBoxDC;
    private javax.swing.JComboBox jComboBoxCL;
    private javax.swing.JComboBox jComboBoxColorQuality;
    private javax.swing.JComboBox jComboBoxSc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuItem jMenuItemReceiveFiles;
    private javax.swing.JMenuItem jMenuItemSendFiles;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu jPopupMenuFileTranfer;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JToolBar.Separator jSeparator7;
    private javax.swing.JToolBar.Separator jSeparator8;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    // End of variables declaration//GEN-END:variables
    
}
